package main

import (
	"github.com/kataras/iris/v12"
	"golearning_iris/controller"
	"golearning_iris/gt"
	"golearning_iris/middleware"
	"log"
)

func main() {
	//全局路由
	gt.App.UseGlobal(middleware.MyMiddleware)
	gt.App.UseGlobal(middleware.StartTime)

	gt.App.DoneGlobal(middleware.MyMiddleware)
	gt.App.DoneGlobal(middleware.EndTime)
	controller.InitRoutes()
	err := gt.App.Run(iris.Addr(":8080"))
	if err != nil {
		log.Fatal(err)
	}
}

//func main() {
//	app := iris.New()
//	app.Get("/", func(ctx iris.Context) { ctx.Redirect("/example") })
//
//	// example := app.Party("/example")
//	// example.SetExecutionRules && mvc.New(example) or...
//	m := mvc.New(app.Party("/example"))
//
//	// IMPORTANT
//	// All options can be filled with Force:true, they all play nice together.
//	m.Router.SetExecutionRules(iris.ExecutionRules{
//		// Begin:  <- from `Use[all]` to `Handle[last]` future route handlers, execute all, execute all even if `ctx.Next()` is missing.
//		// Main:   <- all `Handle` future route handlers, execute all >> >>.
//		Done: iris.ExecutionOptions{Force: true}, // <- from `Handle[last]` to `Done[all]` future route handlers, execute all >> >>.
//	})
//	m.Router.Done(doneHandler)
//	// m.Router.Done(...)
//	// ...
//	//
//
//	m.Handle(&exampleController{})
//
//	app.Run(iris.Addr(":8080"))
//}
//
//func doneHandler(ctx iris.Context) {
//	ctx.WriteString("\nFrom Done Handler")
//}
//
//type exampleController struct{}
//
//func (c *exampleController) Get() string {
//	return "From Main Handler"
//	// Note that here we don't binding the `Context`, and we don't call its `Next()`
//	// function in order to call the `doneHandler`,
//	// this is done automatically for us because we changed the execution rules with the `SetExecutionRules`.
//	//
//	// Therefore the final output is:
//	// From Main Handler
//	// From Done Handler
//}

//func main() {
//	app := iris.New()
//	app.Get("/ping", func(ctx context.Context) {
//		ctx.JSON(iris.Map{"msg": "pong"})
//		ctx.Next()
//	})
//
//}

//func main() {
//	app := iris.New()
//	mvc.Configure(app.Party("/root"), myMVC)
//	mvc.New(app)
//	app.Run(iris.Addr(":8080"))
//}
//
//type MyController struct {
//}
//
//func myMVC(app *mvc.Application) {
//	app.Handle(new(MyController))
//
//}
//
//func (c *MyController) BeforeActivation(b mvc.BeforeActivation) {
//	b.Handle("GET", "/abc/{id:long}", "MyCustomHandler")
//	b.Handle("GET", "/edf/{id:long}", "MyCustomHandler")
//}
//
//func (c *MyController) Get() string {
//	return "Hey"
//}
//
//func (c *MyController) MyCustomHandler(id int64) string {
//	return "MyCustomHandler says Hey"
//}
